package com.example.demo.mapper;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.bean.PageRes;
import com.example.demo.bean.SysJob;
import com.example.demo.bean.SysJobLog;
import com.example.demo.dto.task.SysJobLogPageReqVO;
import com.example.demo.dto.task.SysJobPageReqVO;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface SysJobLogMapper extends BaseMapperX<SysJobLog>{
    default PageRes<SysJobLog> selectPage(SysJobLogPageReqVO reqVO){
        Page<SysJobLog> page = new Page<>(reqVO.getPageNo(), reqVO.getPageSize());
        return selectPageCommon(page,new QueryWrapper<SysJobLog>()
                .like(ObjectUtil.isNotNull(reqVO.getJobName()),"job_name",reqVO.getJobName())
                .like(ObjectUtil.isNotNull(reqVO.getJobGroup()),"job_group",reqVO.getJobGroup())
                .eq(ObjectUtil.isNotNull(reqVO.getStatus()),"status",reqVO.getStatus())
                .between(
                        ObjectUtil.isNotNull(reqVO.getTimeArr()),
                        "create_time",
                        ArrayUtil.get(reqVO.getTimeArr(), 0),
                        ArrayUtil.get(reqVO.getTimeArr(), 1)
                )
        );
    }
}
